﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using WS.EKA.Web.UI.Bussiness;

namespace WS.EKA.Web.UI.Demo
{
    public class ReportData : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            string result = GetReport(context);
            context.Response.Write(result);
        }

        public bool IsReusable
        {
            get
            {
                return true;
            }
        }

        private string GetReport(HttpContext context)
        {
            var parameter = new ReportParameter();
            int pageCount = 3;
            int index = 0;
            if (int.TryParse(context.Request.QueryString["PageIndex"], out index))
            {
                parameter.PageIndex = index;
            }
            string reportType = context.Request.QueryString["ReportType"];
            ReportType type = ReportType.None;
            if (Enum.TryParse<ReportType>(reportType, out type))
            {
                parameter.ReportType = type;
            }
            parameter.PageCount = pageCount;
           
            IReport reportService = ReportFactory.GetReportFactory(parameter.ReportType);
            return reportService.GetJsonData(parameter);
        }
    }

}